﻿

local moduleName = "VoiceIcon"



----------------------------
--      Localization      --
----------------------------

local L = {
	[moduleName] = "Voice Icon",
}

if GetLocale() == "zhCN" then
	L[moduleName] = "语音图标"
elseif GetLocale() == "zhTW" then
	L[moduleName] = "語音圖示"
end


----------------------------------
--      Local Declaration      --
----------------------------------



----------------------------------
--      Module Declaration      --
----------------------------------

local plugin = BunchOfBars:NewModule(moduleName)

plugin.revision = tonumber(("$Revision: 40 $"):match("%d+"))

plugin.options = {
	name = L[moduleName],
	args = {
	}
}

plugin.defaultDB = {
	profile = {
		iconsize = 14,
		style = {
			position = "TOPLEFT",
			xof = 20,
			yof = 2,
		}
	}
}
plugin.head = {
	core = true
}
plugin.moduletype = "icon"
----------------------------------
--      Module Functions        --
----------------------------------

function plugin:OnEnable()
	self:RegisterEvent("VOICE_START")
	self:RegisterEvent("VOICE_STOP")
end


function plugin:OnCreate(frame)
	local icon = frame:CreateTexture(nil, "OVERLAY")
	icon:SetHeight(self.db.profile.iconsize)
	icon:SetWidth(self.db.profile.iconsize)
	icon:SetTexture("Interface\\Common\\VoiceChat-Speaker")
	icon:SetTexCoord(0.04, 0.96, 0.04, 0.96)
	icon:ClearAllPoints()
--	icon:SetPoint("CENTER", frame, "CENTER", 0, 0)
	icon:Hide()

	local wave = frame:CreateTexture(nil, "OVERLAY")
	wave:SetHeight(self.db.profile.iconsize)
	wave:SetWidth(self.db.profile.iconsize)
	wave:SetTexture("Interface\\Common\\VoiceChat-On")
	wave:SetTexCoord(0.04, 0.96, 0.04, 0.96)
	wave:ClearAllPoints()
	wave:SetPoint("CENTER", icon, "CENTER", 0, 0)
	wave:Hide()

	icon.wave = wave

	return icon
end

function plugin:VOICE_START(unit)
	if self.core.frames[unit] then
		self.core.frames[unit].parts[moduleName]:Show()
		self.core.frames[unit].parts[moduleName].wave:Show()
	end
end


function plugin:VOICE_STOP(unit)
	if self.core.frames[unit] then
		self.core.frames[unit].parts[moduleName]:Hide()
		self.core.frames[unit].parts[moduleName].wave:Hide()
	end
end



----------------------------------
--      Option Handlers         --
----------------------------------
function plugin:SetIconSize()
	self:UpdateAllWith(function(frame)
		frame.parts[moduleName]:SetHeight(self.db.profile.iconsize)
		frame.parts[moduleName]:SetWidth(self.db.profile.iconsize)
		frame.parts[moduleName].wave:SetHeight(self.db.profile.iconsize)
		frame.parts[moduleName].wave:SetWidth(self.db.profile.iconsize)
	end)
end